The techniques disclosed in Japanese Unexamined Patent Publication (Kokai) Nos. 6-4490 "Data Processing System" (hereinafter JP 6-4490) and 6-44195 "Method and Apparatus for a Coupling Type Data Processing System" (hereinafter Jp 6-44195) provide methods for managing resources shared among computers (central processing complex (CPC)) in a general purpose parallel computer system using a coupling facility (structured external storage (SES) facility).
According to JP 6-44195, computers, each being connected to the coupling facility by an intersystem channel, manage shared resources by using shared data objects (two kinds of objects called cache structures and list structures are described) called structures or structure types held in the coupling facility, and processing routines called message manipulation for manipulating objects contained in the structures and structure types. The message manipulation is often called message commands or simply commands. The coupling facility can hold a plurality of structure types which are identified by identifiers called structure identifiers (SID).
A scheme for computers to perform message manipulation using the coupling facility is disclosed in JP 6-4490. According to the scheme, computers start the message manipulation by sending, to the coupling facility, a memory block of a predetermined size called a message command block (MCB) prepared in a memory using an instruction called a message send instruction (SMSG instruction).
According to JP 6-44195, a plurality of commands for manipulating structure types according to their kind are defined in advance in the coupling facility, and the computers start message manipulation by sending an MCB in which commands are specified, to the coupling facility via an intersystem channel by using an SMSG instruction. The started message manipulation sets execution results in a memory block of a predetermined size called a message response block (MRB), and terminates the message manipulation by sending back the MRB to the computer which sent the commands. The MCB can contain an SID to specify a structure type which is subject to the message manipulation to be started.
Of the two kinds of structure types described in JP 6-44195, a list structure type can contain a lock table consisting of several lock table items. Several lock-only commands for manipulating a lock table are defined in the lock table. The structure of the lock table and the lock-only commands are disclosed in JP 6-44195.
The following brief discussion relates to a method for managing resources shared among computers by using the techniques described in JP 6-4490 and JP 6-44195 in a general purpose parallel computer system which employs the coupling facility.
By using a proper lock-only command, one lock table item can be updated only when conditions are satisfied, and whether the updating succeeded or failed can be determined from an MRB of the command. Detailed conditions in which the updating of a lock table by lock-only commands succeeds or fails are described in JP 6-44195. The commands allow lock table items to be used to indicate the status of shared resources. Generally, objects used to indicate the status of shared resources such as table items are called "locks".
A computer program which uses shared resources predetermine a value indicating that shared resources are being used. The program also predetermines a value indicating that shared resources are not used by any program (called free state).
When a program starts to use a shared resource, a lock-only command is used to write to a lock table item a value that the shared resource is being used, only when a lock table item corresponding to the shared resource indicates the free state of the shared resource. Sending such a command to the coupling facility is called a "lock reservation request". If the updating of a lock table item by the command, that is, lock reservation succeeds, the shared resource can be used by the program that sent the lock-only command, and the program can start processing using the shared resource.
When lock reservation fails (when the updating of a lock table item by a lock-only command described previously fails), it indicates that the shared resource is being used by another program. In this case, a program which attempts to start the use of the shared resource waits for the lock to be freed (eventually the resource is freed) by another program, by repeatedly sending the same command to the coupling facility until lock reservation succeeds.
The program which terminates the use of the shared resource sends a lock-only command to write a value indicating the free state of the shared resource to a corresponding lock table item. Sending such a command to the coupling facility is called "freeing a lock". When a program keeping the lock frees the shared resource, the program waiting for the lock to be freed which repeatedly issued the lock reservation request, succeeds, and starts processing using the shared resource.
Thus, a method for managing resources shared among computers can be provided.
When a process requires access to a shared resource, the shared resource is exclusively controlled for management among a plurality of processes in such a way that the process loops wait until the shared resource becomes available to them. This is generally called a spin type exclusive control, which is the base of exclusive control in a computer system in which a plurality of processes operate in parallel. Exclusive control processing used therein is called spin locking. Here, a process refers to all processing performed in a computer system.
Spin locking is implemented by the known method of using a TEST AND SET LOCK instruction (TSL instruction) described on Pages 38 and 39 in "Modern Operating Systems (by Andrew S. Tanenbaum) or similar instructions, for example. This method is primarily used to implement spin locking among instruction processing units in a computer having a tightly coupled multiprocessor configuration in which a plurality of instruction processing units share one main storage. In this case, a process is an instruction processing unit.
By using the lock table and lock-only commands of the coupling facility described in JP 6-44195, spin locking can be implemented among programs on computers in a general purpose parallel computer system using the coupling facility. In this case, a process is a program on a computer.
In the spin locking, a process using a shared resource waits until a lock corresponding to the shared resource can be reserved, then performs processing using the shared resource, and at termination of the processing, frees the lock to notify other processes of the fact.
The "lock" in spin locking refers to the (one) word in memory when the spin locking is implemented using a TSL instruction described previously, and the (one) lock table item when implemented using a lock table and lock-only commands. By associating these locks with shared resources, the reservation of shared resources is replaced by the reservation of locks.
A value can be set in a lock to indicate whether a shared resource is being used by processes or is not being used by any process (in a free state). The value is predetermined.
A request to reserve a lock in the spin locking is an attempt for a process to set in the lock the value indicating that it is using a shared resource. However, only when a value indicating the free state of a resource is set in the lock, the lock can be updated to a value indicating that the resource is being used, and it is therefore necessary to perform in combination the checking for a free state and the setting of a use indication. The TSL instruction and lock-only commands described previously ensure that the checking of an old value and the setting of a new value are performed in combination. Successful setting of a use indication in a lock is referred to as a "process reserving a lock".
When the setting of a value in a lock fails, a process repeats the same operation until it succeeds. This repetition is called "lock wait spin". Thus, waiting by simple loop processing for a lock to be reserved is the characteristic being in lock wait spin.
"Freeing a lock" means the setting, in a lock, of a value indicating that a shared resource is not being used. In this way, since a lock reservation request made repeatedly by a process waiting for the lock to be freed succeeds, a program having reserved the lock can start processing using the shared resource.
FIG. 12 is an example of a resource management table used when resources are exclusively controlled using the spin locking. A resource management table 1200 has lines 1210-1 to 1210-j, which are associated with resources 1220-i to 1220-j, respectively, by resource pointer 1240. Each line 1210 contains a lock 1230. When accessing a shared resource 1220, a process issues a request to reserve a lock 1230 corresponding to it, and reserves the lock 1230 before accessing a shared resource 1220.
The reservation of the lock 1230 falls into two attributes, depending on the type of access to the shared resource 1220: shared and exclusive. The reservation of the lock 1230 with an exclusive attribute is to permit only one process to reserve the lock 1230. A request to reserve the lock 1230 with an exclusive attribute is accepted only when no other process reserves the lock 1230. On the other hand, the reservation of the lock 1230 with a shared attribute is to permit a plurality of processes to reserve the lock 1230 if all of them attempt to reserve the lock with a shared attribute. A request to reserve the lock 1230 with a shared attribute is accepted unless other processes exclusively reserve the lock 1230.
To be brief, processes that only read the shared resource 1220 without modifying it reserve the lock 1230 corresponding to the resource with a shared attribute, and processes that modify the resource reserve the lock 1230 corresponding to the resource with an exclusive attribute. Thus, processes that perform only reading can access the shared resource 1220 at the same time.
FIG. 13 is a flowchart showing resource exclusive processing using the spin locking. It is a flowchart showing lock reservation states when processes A, B, and C request one shared resource 1220 with shared, exclusive, and shared attributes in that order.
To gain shared access to the shared resource 1220, process A first issues a request to reserve a corresponding lock 1230 with a shared attribute (step 1300). Since the lock 1230 is not reserved by any process at this point, it is immediately reserved by the process A with a shared attribute (step 1301). Then, the process A accesses the shared resource 1220 with a shared attribute and performs necessary processing (step 1302).
Suppose that exclusive access to the shared resource 1220 has become necessary in step B when the process A is executing step 1302. Accordingly, the process B issues a request to exclusively reserve a corresponding lock 1230 (step 1304). However, since the process A is executing step 1302, the lock 1230 is reserved with a shared attribute by the process A and the process B cannot exclusively reserve the lock 1230. The process B keeps spinning until the lock 1230 is freed (step 1305).
At this time (when the process B is executing step 1305), suppose that shared access to the shared resource 1220 has become necessary in process C. Accordingly, the process C issues a request to reserve a corresponding lock 1230 with a shared attribute (step 1307).
At his point, the process B has not yet exclusively reserved the lock 1230, which is still reserved with a shared attribute by the process A. Since process C also has a shared reservation attribute (the same as process A), it can reserve the lock 1230 without spinning to wait for the lock, and can immediately access the shared resource 1220 with a shared attribute (step 1309). Meanwhile, the process B still waits for the lock to be freed, in step 1305.
Suppose that the use of the shared resource initiated in step 1302 terminates in the process A and the lock 1230 is freed (step 1303, time t11 in FIG. 13). However, at this stage, the process B is in lock wait spin waiting for the lock 1230 to be freed and cannot yet reserve it with an exclusive attribute. This is because the lock 1230 is already reserved with a shared attribute by the process C. The process B cannot reserve the lock 1230 until the process C terminates use of the shared resource at step 1309 and frees the lock 1230 in step 1310. At this point (time t12), the process B can exclusively reserve the lock 1230 (step 1306) and can start processing using the shared resource 1220.
Although in FIG. 13, it is shown that only three processes access shared resources for convenience of explanation, more processes can generally exist. When the process C is executing step 1309, if another process attempts to gain shared access to the shared resource 1220, it can access the lock 1230 with a shared attribute just like the process C. As a result, further delay occurs before process B can exclusively reserve the lock 1230 (step 1306).
The flow of a series of processes can be repeated indefinitely. Accordingly, although each of the individual processes that reserve the lock 1230 with a shared attribute frees the lock 1230 after a limited period of time elapses, there occurs the situation where the process B cannot reserve the lock 1230 for an indefinite period of time. This is referred to as the aborting of preceding exclusive reservation requests due to preference for following shared reservation requests.